﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.SqlClient;

public partial class admin_SQL : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        bool nav = false;
        try
        {
            using (SqlConnection conn = new SqlConnection("Data Source=RATKO-PC;Initial Catalog=nMuratovski_tx;User id=test; Password=test;MultipleActiveResultSets=True"))
            {
                conn.Open();
                string q = TextBox1.Text;
                using (SqlCommand cmd = new SqlCommand(TextBox1.Text, conn))
                {
                    cmd.CommandType = System.Data.CommandType.Text;
                    int val = cmd.ExecuteNonQuery();
                    Session["message"] = "OK";
                    Session["message_type_css"] = "par_message_ok";
                    nav = true;
                    //if (q.Contains("SELECT") || q.Contains("Select") || q.Contains("select"))
                    //{
                    //    SqlDataReader dr = cmd.ExecuteReader();
                    //    string data = "";
                    //    while (dr.Read())
                    //    {
                    //        int colums = dr.FieldCount;
                    //        data += "{";
                    //        for (int i = 0; i < colums; i++)
                    //        {
                    //            data += dr[i] + ",";
                    //        }
                    //        data += "}\n";
                    //    }
                    //    TextBox1.Text = data;
                    //    Session["message"] = "OK";
                    //    Session["message_type_css"] = "par_message_ok";
                    //}
                    //else
                    //{
                    //    int val = cmd.ExecuteNonQuery();
                    //    Session["message"] = "OK";
                    //    Session["message_type_css"] = "par_message_ok";
                    //    nav = true;
                    //}
                }
            }
        }
        catch (Exception ex)
        {
            Session["message"] = "NOK "+ex.ToString();
            Session["message_type_css"] = "par_message_error";
            nav = true;
        }
        if(nav) Response.Redirect(Request.Url.ToString());
    }
}
